package com.tim.app.ui.adapter.search;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.application.library.widget.recycle.BaseRecyclerAdapter;
import com.tim.app.R;
import com.tim.app.server.entry.Answer;
import com.tim.app.util.TextUtil;

import java.util.List;


/**
 * 回答
 */
public class SearchAnswerAdapter extends BaseRecyclerAdapter<BaseRecyclerAdapter.BaseRecyclerViewHolder, Answer> {

    private Context mContext;

    private String keyWord = "";

    public SearchAnswerAdapter(Context mContext, List<Answer> mDataList) {
        super(mDataList);
        this.mContext = mContext;
    }

    public String getKeyWord() {
        return keyWord;
    }

    public void setKeyWord(String keyWord) {
        this.keyWord = keyWord;
    }

    @Override
    public BaseRecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        BaseRecyclerViewHolder holder = null;
        holder = new ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.cell_search_answer, parent, false));
        return holder;
    }

    @Override
    public void onBindViewHolder(BaseRecyclerViewHolder mHolder, int position, Answer data) {
        if (data == null) {
            return;
        }
        final ViewHolder holder = (ViewHolder) mHolder;
        if (!TextUtils.isEmpty(data.getProblemTitle())) {
            TextUtil.setTextHighLight(holder.tvInfoTitle, getKeyWord(), data.getProblemTitle());
        }
        if (!TextUtils.isEmpty(data.getContent())) {
            TextUtil.setTextHighLight(holder.tvInfoDesc, getKeyWord(), data.getContent());
        }
        holder.tvSearchPriseNumber.setText(mContext.getString(R.string.searchAnswerPriseNumber, String.valueOf(data.getAgreeCount())));

        holder.tvSearchCommentNumber.setText(mContext.getString(R.string.searchAnswerCommentNumber, String.valueOf(data.getCommentCount())));
    }

    public class ViewHolder extends BaseRecyclerViewHolder {

        TextView tvInfoTitle, tvInfoDesc;
        TextView tvSearchPriseNumber, tvSearchCommentNumber;
        View vLine;

        public ViewHolder(View itemView) {
            super(itemView);
            tvInfoTitle = (TextView) itemView.findViewById(R.id.tvInfoTitle);
            tvInfoDesc = (TextView) itemView.findViewById(R.id.tvInfoDesc);
            tvSearchPriseNumber = (TextView) itemView.findViewById(R.id.tvSearchPriseNumber);
            tvSearchCommentNumber = (TextView) itemView.findViewById(R.id.tvSearchCommentNumber);
            vLine = itemView.findViewById(R.id.vLine);
        }

    }

}
